package com.yzion.baselib.view

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.annotation.IdRes
import androidx.annotation.LayoutRes

/**
 * 简单的自定义视图基类
 */
abstract class BaseView : FrameLayout {

    lateinit var view: View

    constructor(context: Context) : super(context) {
        initLayout(context)
        initView(context, null, 0)
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        initLayout(context)
        initView(context, attrs, 0)
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        initLayout(context)
        initView(context, attrs, defStyleAttr)
    }


    private fun initLayout(context: Context) {
        view = inflate(context, getLayoutId(), null)
        addView(view)
    }

    @LayoutRes
    abstract fun getLayoutId(): Int

    abstract fun initView(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
}